package main

// 比较大小的条件有两点， 1. 时间 2. 字母顺序靠后（越大）
func slowestKey(releaseTimes []int, keysPressed string) byte {
	maxLetter := keysPressed[0]
	maxTime := releaseTimes[0]
	for i := 1; i < len(keysPressed); i++ {
		time := releaseTimes[i] - releaseTimes[i-1]
		if time == maxTime && keysPressed[i] >= maxLetter ||
			time > maxTime {
			maxTime = time
			maxLetter = keysPressed[i]
		}
	}
	return byte(maxLetter)
}

// 官方题解，一样的思路
func slowestKey1(releaseTimes []int, keysPressed string) byte {
	// ans 读取出来就是 byte， 为啥我以为是 int
	ans := keysPressed[0]
	maxTime := releaseTimes[0]
	for i := 1; i < len(keysPressed); i++ {
		key := keysPressed[i]
		time := releaseTimes[i] - releaseTimes[i-1]
		if time > maxTime || time == maxTime && key > ans {
			ans = key
			maxTime = time
		}
	}
	return ans
}
